import * as echarts from "echarts";

const gaugeLineWidth = 8;

/**
 * 仪表盘配置处理方法
 * @param {Object} data 传入相关数据
 * @returns {Object} 返回 Echarts Option 配置
 */
export const gaugeOptionHandler = (data = {}) => {
  return {
    series: {
      type: "gauge",
      title: {
        offsetCenter: [0, "80%"],
        fontSize: 10,
        color: "rgba(255, 255, 255, 0.80)"
      },
      progress: {
        show: true,
        width: gaugeLineWidth,
        itemStyle: {
          color: new echarts.graphic.LinearGradient(
            0,
            0,
            0,
            1,
            [
              {
                offset: 0,
                color: "rgba(135, 205, 255, 0.8)"
              },
              {
                offset: 0.8,
                color: "rgba(255, 255, 255, 0)"
              }
            ],
            false
          )
        }
      },
      axisLine: {
        lineStyle: {
          width: gaugeLineWidth,
          color: [[1, "rgba(255, 255, 255, 0.10)"]]
        }
      },
      radius: "100%",
      axisTick: { show: false },
      splitLine: { show: false },
      axisLabel: { show: false },
      pointer: { show: false },
      detail: {
        offsetCenter: [0, 0],
        fontSize: 20,
        color: "#fff",
        formatter: value => `${value}%`
      },
      data: [data]
    }
  };
};
